package com.xxgc.eow.service.impl;

import com.github.pagehelper.PageHelper;
import com.xxgc.eow.entity.CollectCommentSecondary;
import com.xxgc.eow.entity.Collectcomment;
import com.xxgc.eow.entity.Likecomment;
import com.xxgc.eow.mapper.CollectcommentMapper;
import com.xxgc.eow.service.ICollectcommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 收藏评论表 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-24
 */
@Service
public class CollectcommentServiceImpl extends ServiceImpl<CollectcommentMapper, Collectcomment> implements ICollectcommentService {

    @Resource
    private CollectcommentMapper CollectcommentMapper;

    @Override
    public List<Collectcomment> getAllCollectCommentsByUserId(Integer userId) {
        return CollectcommentMapper.selectAllByUserId(userId);
    }

    @Override
    public List<CollectCommentSecondary> selectAll(int PageNum,int PageSize) {
        PageHelper.startPage(PageNum,PageSize);
        return CollectcommentMapper.selectAll();
    }


    @Override
    public int insertLikeComment(CollectCommentSecondary collectCommentSecondary) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        collectCommentSecondary.setCreateTime(localDateTime);
        return CollectcommentMapper.insertLikeComment(collectCommentSecondary);
    }

    @Override
    public Integer getCommentLikeById(int commentId) {
        return CollectcommentMapper.getLikeNumByCommentId(commentId);
    }

    @Override
    public int updateCommentLike(int commentId, int collectNum) {
        return CollectcommentMapper.updateCommentLike(commentId,collectNum);
    }

    @Override
    public int delCommentLike(CollectCommentSecondary collectCommentSecondary) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        collectCommentSecondary.setDestroyTime(localDateTime);
        return CollectcommentMapper.delLikeComment(collectCommentSecondary);
    }

    @Override
    public CollectCommentSecondary selectDataTf(CollectCommentSecondary collectCommentSecondary) {
        return CollectcommentMapper.selectDataTf(collectCommentSecondary);
    }
}
